<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
/***************************
傳進參數
GambleID：操盤序號
Bet_Type：下注種類
OddsID：賠率序號
Odds：賠率值
LottoID：樂透種類序號
Number：號碼
***************************/
include_once("../config.inc.php");

session_start();
$objMemberInfo = $_SESSION["Member_Info"];
if(time() - $objMemberInfo -> WagerCommonTime <= 1){
	sleep(1);
}
$_SESSION["Member_Info"] -> WagerCommonTime = time();
$_LangPath = "wagercommon";	//語言檔參數，務必放在最前面
include_once(__Member_Path."/logincheck.php");
include_once(__Language_Path."/selectlanguage_member.php");
include_once(__Modules_Path."/Wager.lib.php");
include_once(__Modules_Path."/WagerForm.lib.php");
include_once(__Common_Path."/Lotto.inc.php");
if($objMemberInfo -> isLock == '2'){
	$GLOBALS["errormessage"] = $_strStopWager;
	include("wager_error.php");
}

$intLID = (int)$_data["LottoID"];
$intGID = (int)$_data["GambleID"];
$intLType = (int)$_arrLotto[$intLID]["LType"];
$intBT = (int)$_data["Bet_Type"];
$intNum = (int)$_data["Number"];
//找出 Apoint
$intAN = (int)$_arrGLineNumToApointNum[$intLID][$intBT][$intNum];

//print_r($_data["ChoiceNumber"]);
$arrChoiceNumber = $_data["ChoiceNumber"];
$strChoiceNumber = "";
$arrLotto = $_arrLotto[$intLID];

if($intLType == 2){
	if($intBT >= 78 && $intBT <= 83)krsort($arrChoiceNumber);
	if($intBT >= 69 && $intBT <= 77){
		foreach($arrChoiceNumber[$intBT] as $k => $v){
			$arrTmp[] = $k;
		}
		sort($arrTmp);
		$arrChoiceNumber = $arrTmp;
		$strChoiceNumber = implode(",", $arrChoiceNumber);
	}
}

$intOddsID = (int)$_data["OddsID"];
$flOdds = (float)$_data["Odds"];
$intStakeMoney = trim($_data["StakeMoney"]);
include_once(__Common_Path."/betparam/BetParam_".$intLID.".inc.php");
include_once(__Common_Path."/limit/LottoLimit_".$intLID.".inc.php");
include_once(__Common_Path."/ExchangeRate.inc.php");
include_once(__Modules_Path."/RealBet.lib.php");
include_once(__Modules_Path."/Odds.lib.php");
if(__isConnectToOtherWeb == 1){
	$flMemERate = (empty($objMemberInfo -> ExRate))?1:$objMemberInfo -> ExRate;
}else{
	$flMemERate = (empty($_ECRate[$objMemberInfo -> ERID]["Rate"]))?1:$_ECRate[$objMemberInfo -> ERID]["Rate"];
}

if(!is_array($_arrBetParam[$intBT][$intAN])){
	$Err_Message = "No Wager Relation Data!!";
	include("wager_error.php");
}

//賠率轉換值
$flOddsPlus = 0;
if($intLID == 4){
	include_once(__Common_Path."/CommToOddsRate_".$intLID.".inc.php");
	include_once(__Modules_Path."/Commission.lib.php");
	//找出 使用者 的賠率兌換，傳回陣列
	$arrUserOPlus = getUserCommToOdds($objMemberInfo -> ID, $intLID, array($intBT));
	if($arrUserOPlus === false)ErrMsgOutputHTML("Error", "", 1);
	$flOddsPlus = $arrUserOPlus[$intBT][$intAN][11] * $_arrChRate[$intBT][$intAN][$objMemberInfo -> GambleType+10];
}

//取得最新號碼賠率資料
$arrGameDate = getWagerArrayData($intLID, $intLType, $intGID, $intBT, $intNum, $intOddsID, $flOdds, $strChoiceNumber);
if($arrGameDate["isError"]){
	//print $intLID."=".$intGID."=".$intBT."=".$intNum."=".$intOddsID."=".$flOdds;
	$Err_Message = $_strWagerCommon[$arrGameDate["Err_Message"]];
	include("wager_error.php");
}
//print_r($arrChoiceNumber);
//是否上層停押
/*$strParentID = $objMemberInfo -> SubID.",".$objMemberInfo -> MainID.",".$objMemberInfo -> StockID;
if(!$strTop = GetOneStopWagerBet($intGID, $intBT, $intNum, $strParentID)){
	$Err_Message = $GLOBALS["errormessage"];
	$Err_HiddenMessage = $GLOBALS["errorhidden"];
	include("wager_error.php");
}

if($strTop == "Stop"){
	$Err_Message = $_strWagerCommon["StopWager"];
	include("wager_error.php");
}*/

include_once(__Root_Path."/tmp/credit-".$objMemberInfo -> ID.".php");
$flOdds = floatval($arrGameDate["Odds"]) + $flOddsPlus;

$intApointNum = $_arrGLineNumToApointNum[$intLID][$intBT][$intNum];
if($intApointNum == null)$intApointNum = 0;
//加進分盤資料
include_once(__Common_Path."/gambletype/GambleType".$objMemberInfo -> GambleType."_".$intLID.".inc.php");
$flOdds += $_arrGambleType[$arrGameDate["Bet_Type"]][$intApointNum];

if($intLType == 2 && $intBT == 83){
	$flOdds = $flOdds*1000 / (sizeof($arrChoiceNumber[1])*sizeof($arrChoiceNumber[2])*sizeof($arrChoiceNumber[3]));
	$flOdds = floor($flOdds*10)/10;

}else{
	$flOdds = ConvertOddsPlus($intLType, $intBT, $flOdds);
}


if($intLType == 2 && $intBT >= 69 && $intBT <= 83){
	$strWagerConditions = getWagerConditions($intLType, $arrGameDate["Bet_Type"], $arrGameDate["Number"], $flOdds, $arrGameDate["SerialNo"], 0, $arrChoiceNumber, 1);
}else{
	$strWagerConditions = getWagerConditions($intLType, $arrGameDate["Bet_Type"], $arrGameDate["Number"], $flOdds, $arrGameDate["SerialNo"]);
}
$strWagerConditions = WagerFormTrans($arrGameDate["LottoID"], $arrGameDate["Bet_Type"], $strWagerConditions);

$fp = @file(__Membertemplate_Path."/wager_common.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);
$fp = str_replace("{sid}", $_data["sid"], $fp);
$fp = str_replace("{ShowAccount}", $objMemberInfo -> Account, $fp);
$fp = str_replace("{ShowCredit}", $objMemberInfo -> CreditLine, $fp);
$fp = str_replace("{BetTypeName}", $_arrBet_Type[$arrLotto["LType"]][$intBT], $fp);
$fp = str_replace("{LottoName}", $arrLotto["Lotto_".$_intLang], $fp);
$fp = str_replace("{GambleIDValue}", $arrGameDate["GambleID"], $fp);
$fp = str_replace("{Bet_TypeValue}", $arrGameDate["Bet_Type"], $fp);
$fp = str_replace("{OddsIDValue}", $arrGameDate["OddsID"], $fp);
$fp = str_replace("{OddsValue}", $flOdds, $fp);
$fp = str_replace("{LottoIDValue}", $arrGameDate["LottoID"], $fp);
$fp = str_replace("{NumberValue}", $arrGameDate["Number"], $fp);
$fp = str_replace("{UserIDValue}", $objMemberInfo -> ID, $fp);
$fp = str_replace("{WagerConditions}", $strWagerConditions, $fp);
$fp = str_replace("{MinStake}", (string)floor($_arrBetParam[$arrGameDate["Bet_Type"]][$intAN]["MinStake"] / $flMemERate), $fp);	//最小下注金額
$fp = str_replace("{MaxPayOff}", floor($_arrBetParam[$arrGameDate["Bet_Type"]][$intAN]["MaxPayOff"] / $flMemERate), $fp);	//最高派彩
$fp = str_replace("{BetLimit}", $objMemberInfo -> arrBetLimit[$intLID][$arrGameDate["Bet_Type"]], $fp);	//單注限額
$fp = str_replace("{EventLimit}", $objMemberInfo -> arrEventLimit[$intLID][$arrGameDate["Bet_Type"]], $fp);	//單號限額
$fp = str_replace("{ShowStakeMoney}", $intStakeMoney, $fp);
if($intLType == 2 && $intBT >= 78 && $intBT <= 83){
	foreach($arrChoiceNumber as $k => $arrCN){
		$strShowChoiceNumber .= join("x", $arrCN).",";
	}
	$strShowChoiceNumber = substr($strShowChoiceNumber, 0, -1);
	$fp = str_replace("{ShowChoiceNumber}", $strShowChoiceNumber, $fp);
}else{
	$fp = str_replace("{ShowChoiceNumber}", ((is_array($arrChoiceNumber))?join(",", $arrChoiceNumber):""), $fp);
}

//當會員單場限額，大於此樂透單場限額
$chkEventLimit = $objMemberInfo -> arrEventLimit[$intLID][$arrGameDate["Bet_Type"]];
$arrOtherMessage = array();
$_arrLottoLimit[$arrGameDate["Bet_Type"]][0] = floor($_arrLottoLimit[$arrGameDate["Bet_Type"]][0] / $flMemERate);
if($chkEventLimit > $_arrLottoLimit[$arrGameDate["Bet_Type"]][0]){
	$chkEventLimit = $_arrLottoLimit[$arrGameDate["Bet_Type"]][0];
	$arrOtherMessage[0] = $_strWagerCommon["MaxEventLimit"].$chkEventLimit;
}
//當會員單注限額，大於此樂透單注限額
$chkBetLimit = $objMemberInfo -> arrBetLimit[$intLID][$arrGameDate["Bet_Type"]];
$_arrLottoLimit[$arrGameDate["Bet_Type"]][1] = floor($_arrLottoLimit[$arrGameDate["Bet_Type"]][1] / $flMemERate);
if($chkBetLimit > $_arrLottoLimit[$arrGameDate["Bet_Type"]][1]){
	$chkBetLimit = $_arrLottoLimit[$arrGameDate["Bet_Type"]][1];
	$arrOtherMessage[1] = $_strWagerCommon["MaxBetLimit"].$chkBetLimit;
}
//當會員單注限額，大於公司預收單注限額
$CompBetLimit = floor($_arrBetParam[$arrGameDate["Bet_Type"]][$intAN]["Com_BetLimit"] / ($objMemberInfo -> Layer6Scale*$flMemERate));
if($chkBetLimit > $CompBetLimit){
	$chkBetLimit = $CompBetLimit;
	$arrOtherMessage[1] = $_strWagerCommon["MaxBetLimit"].$chkBetLimit;
}
if(sizeof($arrOtherMessage)){
	$fp = str_replace("{OtherMessage}", join("<br>", $arrOtherMessage), $fp);
}else{
	$fp = str_replace("{OtherMessage}", "", $fp);
}
$fp = str_replace("{chkBetLimit}", $chkBetLimit, $fp);
$fp = str_replace("{chkEventLimit}", $chkEventLimit, $fp);

$intTmp = $_arrMemStake[$arrGameDate["Bet_Type"]][$arrGameDate["GambleID"]][$arrGameDate["Number"]];

//3x3x3 等下注用另外限額統計方法(採 JoinNumber 統計)
if($intLType == 2 && $arrGameDate["Bet_Type"] >= 78 && $arrGameDate["Bet_Type"] <= 83){
	foreach($arrChoiceNumber as $k => $arrCN){
		$strT = chr(64 + $k);
		sort($arrCN);
		$strCNumber .= $strT.join($strT, $arrCN)."-";
	}
	$strCNumber = substr($strCNumber, 0, -1);

	$intTmp = getWagerLimitGoldByJoinNumber($objMemberInfo -> ID, $intGID, $intBT, $strCNumber, 0);
	if($intEvent === false){
		PMA_mysql_query("ROLLBACK", $_ConnMaster);
		$Err_Message = ($_strWagerInsert[$GLOBALS["errormessage"]] != "")?$_strWagerInsert[$GLOBALS["errormessage"]]:$GLOBALS["errormessage"];
		$Err_HiddenMessage = $GLOBALS["errorhidden"];
		include("wager_error.php");
	}
}

if(empty($intTmp))$intTmp = 0;
$fp = str_replace("{UseLimitValue}",$intTmp, $fp);	//已使用單場限額額度
$intTmp = $_arrMemStake["_SUM"];
if(empty($intTmp))$intTmp = 0;
$fp = str_replace("{UseCreditValue}",$intTmp, $fp);	//已使用信用額度

$arrCheckKey = split(" ",microtime());
$fp = str_replace("{CheckKeyValue1}", $arrCheckKey[0], $fp);
$fp = str_replace("{CheckKeyValue2}", $arrCheckKey[1], $fp);

if($arrGameDate["isMessage"]){
	$fp = str_replace("{WagerMessage}", $_strWagerCommon[$arrGameDate["Message"]], $fp);
}else{
	$fp = str_replace("{WagerMessage}", "", $fp);
}

while(list($k, $v) = each($_strWagerCommon)){
	$fp = str_replace("{".$k."}", $v, $fp);
}

//輸出
WebOutputHTML($fp, 1);
?>